package org.windchill955.common;

import org.windchill955.NWTException;
import wt.enterprise.RevisionControlled;
import wt.fc.QueryResult;
import wt.util.WTException;
import wt.vc.Mastered;
import wt.vc.VersionControlHelper;
import wt.vc.config.LatestConfigSpec;

/**
 * 通用工具类
 *
 * @author pyk13
 * @version 0.1
 */
public class ToolUtil {
    private ToolUtil() {
    }

    private static final LatestConfigSpec CONFIG_SPEC = new LatestConfigSpec();

    /**
     * 获取最新版本对象
     *
     * @param master 主对象
     * @return 最新版本对象
     */
    public static RevisionControlled getLatestPersistable(Mastered master) {
        try {
            QueryResult queryResult = VersionControlHelper.service.allVersionsOf(master);
            queryResult = CONFIG_SPEC.process(queryResult);
            return (RevisionControlled) queryResult.nextElement();
        } catch (WTException e) {
            throw new NWTException(e);
        }
    }
}
